package cts.com.dbmanager.util;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

import cts.com.connection.DbConnection;

public class DMLOperationDbManager {

	public boolean isQueryExecuted(String[] queries)
			throws ClassNotFoundException, SQLException {

		Connection connection = new DbConnection().getConnection();
		Statement statemenet = null;
		boolean success = false;
		try {
			connection.setAutoCommit(false);
			statemenet = connection.createStatement();
			for (String query : queries) {
				statemenet.addBatch(query);
			}
			statemenet.executeBatch();
			success = true;
			System.out
					.println(getClass().getName()
							+ ".isRecordInserted: Insert/Delete Query Executed Successfully");
		} catch (Exception ex) {
			connection.rollback();
			success = false;
			System.err.println("RolledBack:\n" + ex);
		} finally {
			try {
				statemenet.close();
			} catch (SQLException e1) {
				System.err.println("Statement Close Exception:" + e1);
				success = false;
			}
			try {
				connection.setAutoCommit(true);
				connection.close();
			} catch (SQLException e) {
				System.err.println("Connection Close Exception:" + e);
				success = false;
			}
		}
		return success;
	}

}
